package com.niit.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.Blog;
import com.niit.service.BlogService;
import com.niit.service.impl.BlogServiceImpl;


@WebServlet("/CheckBlogController")
public class CheckBlogController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("blogId");
		boolean checked = "true".equals(request.getParameter("checked"));
		BlogService bs = new BlogServiceImpl();
		Blog blog = bs.findByBlogId(id);		
		blog.setChecked(checked);
		if(blog.isChecked()==true){
			int a = bs.update(blog);
			if(a==0){
				response.getOutputStream().write("审核失败".getBytes());
			}else if(a==1){
				response.getOutputStream().write("审核成功".getBytes());
			}
		}else{
			int a = bs.delete(blog);
			if(a==0){
				response.getOutputStream().write("删除失败".getBytes());
			}else if(a==1){
				response.getOutputStream().write("删除成功".getBytes());
			}
		}
		
	}

}
